﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Instruments
{
    public class DCS_Chroma62024P:Source
    {
        new public static string _sType = "CHROMA,62024P-80-60";

        public DCS_Chroma62024P(string szInsID):base(szInsID)
        {
            _szErrRet = "0,\"No Error\"\n";
        }

        public override bool Init()
        {
            this._ListInitCmd.Add("*CLS\n");
            return base.Init();
        }

        public override void Set_VFC(string Volt, string FC)
        {
            float fCurr = 0;
            if(float.TryParse(Volt, out float fVolt) && float.TryParse(FC, out fCurr))
            {
                _szCmd = "SOUR:VOLT " + Volt + ";CURR " + FC + "\n";
                this.Write(_szCmd);
            }

            if (fVolt.Equals(0) || fCurr.Equals(0))
                this.ONorOFF(false);
            else
                this.ONorOFF(true);
            base.Set_VFC(Volt, FC);
        }

        public override double Meas_Volt()
        {
            _szCmd = "MEAS:VOLT?\n";
            return base.Meas_Volt();
        }

        public override double Meas_Curr()
        {
            _szCmd = "MEAS:CURR?\n";
            return base.Meas_Curr();
        }

        public override double Meas_Power()
        {
            _szCmd = "MEAS:POW?\n";
            return base.Meas_Power();
        }

        public override void ONorOFF(bool NF)
        {
            _szCmd = NF ? "OUTP ON\n" : "OUTP OFF\n";
            this.Write(_szCmd);
        }

        public override bool QueryState()
        {
            return base.QueryState();
        }
    }
}
